<template>
  <!-- 检验项目指标库 -->
  <p-card :bordered="false">
    <!-- 查询区域 -->
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <p-form layout="inline" @keyup.enter.native="searchQuery">
        <p-row :gutter="24">
          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <p-form-item label="检验项目编码">
              <p-input placeholder="请输入检验项目编码" v-model="queryParam.inspectProjectCode"></p-input>
            </p-form-item>
          </p-col>
          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <p-form-item label="检验项目名称">
              <p-input placeholder="请输入检验项目名称" v-model="queryParam.inspectProjectName"></p-input>
            </p-form-item>
          </p-col>

          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <p-form-item label="项目类型">
              <p-select v-model="queryParam.projectTypeId" placeholder="请选择项目类型" @change="projectTypeIdChange2">
                <p-select-option
                        v-for="(item,index) in projectTypeList"
                        :key="index"
                        :value="parseInt(item.value)"
                >{{item.title}}</p-select-option>
              </p-select>

            </p-form-item>
          </p-col>


          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <p-button type="primary" @click="searchQuery" icon="search">查询</p-button>
              <p-button
                      type="primary"
                      @click="searchReset"
                      icon="reload"
                      style="margin-left: 8px"
              >重置</p-button>
               <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <p-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </p-col>
        </p-row>

        <p-row :gutter="24" v-if="toggleSearchStatus">
          <p-col :xl="6" :lg="7" :md="8" :sm="24" v-if="queryParam.projectTypeId&&queryParam.projectTypeId!=''">
            <p-form-item label="项目分类">
              <p-select v-model="queryParam.projectClassifyId" placeholder="请选择项目分类" showSearch v-if="queryParam.projectTypeId==1">
                <p-select-option
                        v-for="(item,index) in projectClassifyListT"
                        :key="index"
                        :value="item.id+'-'+item.mtypename"
                >{{item.mtypename}}</p-select-option>
              </p-select>
              <p-select v-model="queryParam.projectClassifyId" placeholder="请选择项目分类" showSearch v-if="queryParam.projectTypeId==2">
                <p-select-option
                        v-for="(item,index) in projectClassifyListT"
                        :key="index"
                        :value="item.id+'-'+item.processmname"
                >{{item.processmname}}</p-select-option>
              </p-select>

              <p-select v-model="queryParam.projectClassifyId" placeholder="请选择项目分类" showSearch v-if="queryParam.projectTypeId!=2&&queryParam.projectTypeId!=1">
                <p-select-option
                        v-for="(item,index) in projectClassifyListT"
                        :key="index"
                        :value="parseInt(item.value)"
                >{{item.title}}</p-select-option>
              </p-select>

            </p-form-item>

          </p-col>
        </p-row>

      </p-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <p-button @click="openAddBtn" type="primary" icon="plus">新增</p-button>
      <p-button @click="previewBtn" type="primary" icon="eye">预览</p-button>

      <template v-if="cgButtonList && cgButtonList.length>0" v-for="(item,index) in cgButtonList">
        <p-button
                v-if=" item.optType=='js' && (item.groupTag == null || item.groupTag == '' )"
                :key=" 'cgbtn'+index "
                @click="cgButtonJsHandler(item.buttonCode)"
                type="primary"
                :icon="item.buttonIcon"
        >{{ item.buttonName }}</p-button>
        <p-button
                v-else-if=" item.optType=='action' && (item.groupTag == null || item.groupTag == '' )"
                :key=" 'cgbtn'+index "
                @click="cgButtonActionHandler(item.buttonCode)"
                type="primary"
                :icon="item.buttonIcon"
        >{{ item.buttonName }}</p-button>
      </template>

      <!-- 高级查询区域 -->
      <j-super-query
              :fieldList="fieldList"
              ref="superQueryModal"
              @handleSuperQuery="handleSuperQuery"
      ></j-super-query>

      <p-dropdown v-for="(item,index) in groupTag" :key="index">
        <p-button>
          {{item.name}}
          <p-icon type="down" />
        </p-button>
        <p-menu slot="overlay">
          <template v-for="(items,indexs) in item.data">
            <p-menu-item
                    v-if=" items.optType=='js' "
                    :key="indexs"
                    @click="cgButtonJsHandler(items.buttonCode)"
            >
              <p-icon :type="items.buttonIcon" />
              {{items.buttonName}}
            </p-menu-item>
            <p-menu-item
                    v-else-if=" items.optType=='action' "
                    :key="indexs"
                    @click="cgButtonActionHandler(items.buttonCode)"
            >
              <p-icon :type="items.buttonIcon" />
              {{items.buttonName}}
            </p-menu-item>
          </template>
        </p-menu>
      </p-dropdown>

      <p-dropdown v-if="selectedRowKeys.length > 0">
        <p-menu slot="overlay">
          <p-menu-item key="1" @click="batchDel">
            <p-icon type="delete" />删除
          </p-menu-item>
        </p-menu>
        <p-button style="margin-left: 8px">
          批量操作
          <p-icon type="down" />
        </p-button>
      </p-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="poros-alert poros-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle poros-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>

        <span style="float:right;">
          <a @click="handleExportXls('检验项目指标库')">
            <p-icon type="download" />导出
          </a>
          <p-divider type="vertical" />
          <p-upload
                  name="file"
                  :showUploadList="false"
                  :multiple="false"
                  :headers="tokenHeader"
                  :action="importExcelUrl"
                  @change="handleImportExcel"
          >
            <a>
              <p-icon type="import" />导入
            </a>
          </p-upload>
          <p-divider type="vertical" />
          <a @click="loadData()">
            <p-icon type="sync" />刷新
          </a>
          <p-divider type="vertical" />
          <p-popover title="自定义列" trigger="click" placement="leftBottom" :overlay-style="getWidth">
            <template slot="content">
              <p-checkbox-group
                      @change="onColSettingsChange"
                      v-model="settingColumns"
                      :defaultValue="settingColumns"
              >
                <p-row>
                  <template v-for="(item,index) in defColumns">
                    <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                      <p-col :span="12">
                        <p-checkbox :value="item.dataIndex">{{ item.title }}</p-checkbox>
                      </p-col>
                    </template>
                  </template>
                </p-row>
              </p-checkbox-group>
            </template>
            <a>
              <p-icon type="setting" />自定义列
            </a>
          </p-popover>
        </span>
      </div>

      <!-- 表格 -->
      <p-table
              ref="table"
              size="middle"
              bordered
              rowKey="id"
              :columns="columns"
              :dataSource="dataSource"
              :pagination="ipagination"
              :loading="loading"
              :rowSelection="{fixed:true,selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
              @change="handleTableChange"
              :customRow="clickThenSelect"
              :rowClassName="setRowClassName"
              :expandedRowKeys="expandedRowKeys"
              @expand="handleExpand"
              v-bind="tableProps"
      >
        <div
                slot="filterDropdown"
                slot-scope="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"
                style="padding: 8px"
        >
          <p-input
                  v-ant-ref="c => (searchInput = c)"
                  :placeholder="`请输入 ${column.title}`"
                  :value="selectedKeys[0]"
                  style="width: 188px; margin-bottom: 8px; display: block;"
                  @change="e => setSelectedKeys(e.target.value ? [e.target.value] : [])"
          />
          <p-button
                  type="primary"
                  icon="search"
                  size="small"
                  style="width: 90px; margin-right: 8px"
                  @click="() => handleSearch(selectedKeys, confirm, column.dataIndex)"
          >确认</p-button>
          <p-button size="small" style="width: 90px" @click="() => handleReset(clearFilters)">取消</p-button>
        </div>
        <div
                slot="filterDropdownDate"
                slot-scope="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"
                style="padding: 8px"
        >
          <p-form-item :label="` ${column.title}`">
            <j-date
                    :show-time="true"
                    date-format="YYYY-MM-DD HH:mm:ss"
                    placeholder="请选择开始时间"
                    class="query-group-cust"
                    v-model="queryParam[`${column.dataIndex}_begin`]"
            ></j-date>
            <span class="query-group-split-cust"></span>
            <j-date
                    :show-time="true"
                    date-format="YYYY-MM-DD HH:mm:ss"
                    placeholder="请选择结束时间"
                    class="query-group-cust"
                    v-model="queryParam[`${column.dataIndex}_end`]"
            ></j-date>
          </p-form-item>
          <p-button
                  type="primary"
                  icon="search"
                  size="small"
                  style="width: 90px; margin-right: 8px"
                  @click="() => handleSearchDate(selectedKeys, confirm, column.dataIndex)"
          >确认</p-button>
          <p-button
                  size="small"
                  style="width: 90px"
                  @click="() => handleResetDate(clearFilters,`${column.dataIndex}_begin`,`${column.dataIndex}_end`)"
          >取消</p-button>
        </div>
        <p-icon
                slot="filterIcon"
                slot-scope="filtered"
                type="search"
                :style="{ color: filtered ? '#108ee9' : undefined }"
        />


        <template slot="inspectProjectCode" slot-scope="text,record">
          <div>{{text}}</div>
        </template>
        <!-- 状态插槽 -->
        <template slot="status" slot-scope="text,record">
          <div v-if="!text" >/</div>
          <p-tag v-else-if="text==1" color="green"><p-icon type="check-circle" />生效</p-tag>
          <p-tag v-else-if="text==2" color="red"><p-icon type="close-circle" />失效</p-tag>

          <!--  <div v-if="record.status==1" style="color:#00FF00;">生效</div>
            <div v-else style="color: red;">失效</div>-->
        </template>

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <img
                  v-else
                  :src="getImgView(text)"
                  height="25px"
                  alt="图片不存在"
                  style="max-width:80px;font-size: 12px;font-style: italic;"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
          <p-button
                  v-else
                  :ghost="true"
                  type="primary"
                  icon="download"
                  size="small"
                  @click="uploadFile(text)"
          >下载</p-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="openEditBtn(record)">编辑</a>

          <p-divider type="vertical" />
          <p-dropdown>
            <a class="poros-dropdown-link">
              更多
              <p-icon type="down" />
            </a>
            <p-menu slot="overlay">
              <p-menu-item>
                <p-popconfirm title="确定删除吗?" @confirm="() => deleteBtn(record.id)">
                  <a>删除</a>
                </p-popconfirm>
              </p-menu-item>
              <template
                      v-if="cgButtonLinkList && cgButtonLinkList.length>0"
                      v-for="(btnItem,btnIndex) in cgButtonLinkList"
              >
                <p-menu-item :key=" 'cgbtnLink'+btnIndex " v-if="showLinkButton(btnItem,record)">
                  <a
                          href="javascript:void(0);"
                          @click="cgButtonLinkHandler(record,btnItem.buttonCode,btnItem.optType)"
                  >
                    <p-icon v-if="btnItem.buttonIcon" :type="btnItem.buttonIcon" />
                    {{ btnItem.buttonName }}
                  </a>
                </p-menu-item>
              </template>
            </p-menu>
          </p-dropdown>
        </span>
      </p-table>
    </div>
    <!-- table区域-end -->

    <mesQcInspectIndexLibrary-modal ref="modalForm" :EnhanceJS="EnhanceJS" @ok="modalFormOk"></mesQcInspectIndexLibrary-modal>



    <p-drawer
            title="预览"
            placement="right"
            :closable="false"
            :visible="drawerVisible"
            :width="500"
            @close="onDrawerClose"
    >
      <p-input-search style="margin-bottom: 8px;width:300px" placeholder="请输入内容" @change="treeSearchChange"  />

      <template>
        <p-tree
                :expanded-keys="defaultExpandedKeys"
                :tree-data="treeData"
                @expand="onExpand"
        >

          <template slot="title" slot-scope="{ title }" >
            <span v-if="title.indexOf(searchValue) > -1">
              {{ title.substr(0, title.indexOf(searchValue)) }}
              <span style="color: #f50" >{{ searchValue }}</span>
              {{ title.substr(title.indexOf(searchValue) + searchValue.length) }}
            </span>
            <span v-else >{{ title }}</span>
          </template>


          <!--<span v-if="title.indexOf(searchValue) > -1" @click="clickTree(title)">
              {{ title.substr(0, title.indexOf(searchValue)) }}
              <span style="color: #f50" >{{ searchValue }}</span>
              {{ title.substr(title.indexOf(searchValue) + searchValue.length) }}
            </span>
          <span v-else @click="clickTree(title)">{{ title }}</span>-->
        </p-tree>
      </template>



    </p-drawer>


    <p-modal v-model="pModalVisible" :title="pTitle" :width="900" @ok="pModalOk">
      <p-form-model
              ref="ruleForm"
              :model="form"
              :rules="rules"
              :label-col="labelCol" :wrapper-col="wrapperCol"
      >

        <p-form-model-item label="检验项目编码" prop="inspectProjectCode">
          <p-input v-model="form.inspectProjectCode" readOnly></p-input>
        </p-form-model-item>

        <p-form-model-item label="项目类型" prop="projectTypeId">
          <p-select v-model="form.projectTypeId" placeholder="请选择项目类型" @change="projectTypeIdChange">
            <p-select-option
                    v-for="(item,index) in projectTypeList"
                    :key="index"
                    :value="parseInt(item.value)"
            >{{item.title}}</p-select-option>
          </p-select>

        </p-form-model-item>

        <p-form-model-item label="项目分类" prop="projectClassifyId">
          <p-select v-model="form.projectClassifyId" placeholder="请选择项目分类" showSearch v-if="form.projectTypeId==1">
            <p-select-option
                    v-for="(item,index) in projectClassifyList"
                    :key="index"
                    :value="item.id+'-'+item.mtypename"
            >{{item.mtypename}}</p-select-option>
          </p-select>
          <p-select v-model="form.projectClassifyId" placeholder="请选择项目分类" showSearch v-if="form.projectTypeId==2">
            <p-select-option
                    v-for="(item,index) in projectClassifyList"
                    :key="index"
                    :value="item.id+'-'+item.processmname"
            >{{item.processmname}}</p-select-option>
          </p-select>

          <p-select v-model="form.projectClassifyId" placeholder="请选择项目分类" showSearch v-if="form.projectTypeId!=2&&form.projectTypeId!=1">
            <p-select-option
                    v-for="(item,index) in projectClassifyList"
                    :key="index"
                    :value="parseInt(item.value)"
            >{{item.title}}</p-select-option>
          </p-select>
        </p-form-model-item>

        <p-form-model-item label="检验项目名称" prop="inspectProjectName">
          <p-input v-if="currentState==1" v-model="form.inspectProjectName" /> <p-input v-else readOnly v-model="form.inspectProjectName" />
        </p-form-model-item>

<!--        <p-form-model-item label="检验项目名称" prop="inspectProjectName">
          <p-input v-model="form.inspectProjectName"/>
        </p-form-model-item>-->

        <p-form-model-item label="检验值类型" prop="inspectValueType">
          <p-select v-model="form.inspectValueType" placeholder="请选择检验值类型" @change="inspectValueTypeChange" :disabled="currentState==2">
            <p-select-option
                    v-for="(item,index) in inspectValueTypeList"
                    :key="index"
                    :value="parseInt(item.value)"
            >{{item.title}}</p-select-option>
          </p-select>
        </p-form-model-item>

        <p-form-model-item label="检验手段" prop="inspectMethod">
          <p-select v-model="form.inspectMethod" placeholder="请选择项目类型" >
            <p-select-option
                    v-for="(item,index) in methodList"
                    :key="index"
                    :value="parseInt(item.value)"
            >{{item.title}}</p-select-option>
          </p-select>
        </p-form-model-item>

        <!--<p-form-model-item label="检验手段" prop="inspectMethod">
          <p-input v-model="form.inspectMethod"/>
        </p-form-model-item>-->

        <p-form-model-item label="检验标准" prop="inspectStandard">
          <p-input v-model="form.inspectStandard" :disabled="form.inspectValueType==1"/>
        </p-form-model-item>

        <p-form-model-item label="状态" prop="status">
          <p-radio-group v-model="form.status">

            <p-radio :value="1">
              生效
            </p-radio>
            <p-radio :value="2">
              失效
            </p-radio>
          </p-radio-group>
        </p-form-model-item>

      </p-form-model>

    </p-modal>



    <!-- 弹出窗 -->
    <Fx-compontens-modal
            @ok="modalFormOk"
            ref="modalCompon"
            :getList="queryInfo"
            :title="title"
            :dictOptions="dictOptions"
    ></Fx-compontens-modal>
  </p-card>
</template>

<script>
  import { JeecgListMixin } from "@/mixins/JeecgListMixin";
  import { api } from "@/api/manage";
  import JSuperQuery from "@/components/jeecg/JSuperQuery.vue";
  import { filterObj } from "@/utils/util";
  import MesQcInspectIndexLibraryModal from "./modules/MesQcInspectIndexLibraryModal";

  import Vue from "vue";
  import {
    initDictOptions,
    filterMultiDictText,
  } from "@/components/dict/JDictSelectUtil";
  import ButtonExpHandler from "@/components/jeecgbiz/modules/ButtonExpHandler";
  import { postAction, getAction, deleteAction,putAction } from "@/api/manage";
  import FxCompontensModal from "@/components/jeecgbiz/FxCompontensModal";

  //高级查询modal需要参数
  const superQueryFieldList = [
    {
      value: "inspectProjectCode",
      text: "检验项目编码",
      type: "string",
    },
    {
      value: "inspectProjectName",
      text: "检验项目名称",
      type: "string",
    },
    {
      value: "inspectStandard",
      text: "检验标准",
      type: "string",
    },
    {
      value: "inspectValueType",
      text: "检验值类型",
      type: "select",
      dictCode: "inspect_value_type",
    },
    {
      value: "inspectMethod",
      text: "检验手段",
      type: "string",
    },

    {
      value: "createBy",
      text: "创建人",
      type: "string",
    },
    {
      value: "createTime",
      text: "创建日期",
      type: "Date",
    },
    {
      value: "updateBy",
      text: "更新人",
      type: "string",
    },
    {
      value: "updateTime",
      text: "更新日期",
      type: "Date",
    },
    {
      value: "status",
      text: "状态",
      type: "select",
      dictCode: "mes_check",
    },
    {
      value: "remark",
      text: "备注",
      type: "string",
    },

  ];



  export default {
    name: "MesQcInspectIndexLibraryList",
    mixins: [JeecgListMixin],
    components: {
      JSuperQuery,
      FxCompontensModal,
      MesQcInspectIndexLibraryModal,
    },
    data() {
      return {
        fieldList: superQueryFieldList,
        superQueryFlag: false,
        superQueryParams: "",
        description: "检验项目指标库管理页面",
        cgButtonLinkList: [],
        title: "", //存表名
        EnhanceJS: "",
        cgButtonList: [],
        defaultExpandedKeys:[],
        autoExpandParent:false,
        selectTreeKey:[],
        pModalVisible:false,
        pTitle:'',
        labelCol: { span: 6 },
        wrapperCol: { span: 16 },
        currentState:1,
        inspectProjectCode:'',


        editP:{},


        projectTypeList:[],
        projectTypeMap:[],

        projectClassifyList:[],
        projectClassifyListT:[],
        projectClassifyMap:[],
        projectClassifyMapT:[],
        projectClassifyList1:[],
        projectClassifyMap1:[],
        projectClassifyList2:[],
        projectClassifyMap2:[],
        projectClassifyList3:[],
        projectClassifyMap3:[],

        inspectValueTypeList:[],


        form: {
          inspectProjectCode:'',
          projectTypeId:'',
          projectType:'',
          projectClassifyId:'',
          projectClassify:'',
          inspectValueType:'',
          inspectProjectName:'',
          inspectMethod:'',
          inspectStandard:'',
          status:1
        },

        rowId:0,
        rules: {
          projectTypeId: [{ required: true, message: '请选择项目类型', trigger: 'change' }],
          projectClassifyId: [{ required: true, message: '请选择项目分类', trigger: 'change' }],
          inspectValueType: [{ required: true, message: '请选择检验值类型', trigger: 'change' }],
          inspectProjectName: [{ required: true, message: '请输入检验项目名称', trigger: 'change' }],
          inspectMethod: [{ required: true, message: '请输入检验手段', trigger: 'change' }],
          status: [{ required: true, message: '请选择状态', trigger: 'change' }],

        },


        drawerVisible:false,
        treeDataFirst:[],
        treeData:[
          {
            title: 'parent 1',
            key: '0-0',

            children: [
              { title: 'leaf', key: '0-0-0',style:'background-color:yellow;', },
              { title: 'leaf', key: '0-0-1',  },
            ],
          },
        ],

        searchValue:'',

        methodList:[],
        methodMap: [],

        groupTag: [],
        queryInfo: [],
        code: "",
        // 表头
        columns: [],
        //列设置
        settingColumns: [],
        //列定义
        defColumns: [
          {
            title: "序号",
            dataIndex: "",
            key: "rowIndex",
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            },
          },
          {
            title: "检验项目编码",
            align: "center",
            dataIndex: "inspectProjectCode",
            scopedSlots: { customRender: "inspectProjectCode" },
          },
          {
            title: "检验项目名称",
            align: "center",
            dataIndex: "inspectProjectName",
          },
          {
            title: "检验标准",
            align: "center",
            dataIndex: "inspectStandard",
          },
          {
            title: "检验值类型",
            align: "center",
            dataIndex: "inspectValueType_dictText",
          },
          {
            title: "检验手段",
            align: "center",
            dataIndex: "inspectMethod",
            customRender:(text)=>{
              if(!text){
                return "";
              }else{
                if(this.methodMap[text]){
                  return this.methodMap[text].title;
                }
                return  "";
              }
            }
          },
          {
            title: "项目分类",
            align: "center",
            dataIndex: "projectClassify",
          },
          {
            title: "项目类型",
            align: "center",
            dataIndex: "projectType",
          },
          {
            title: "创建人",
            align: "center",
            dataIndex: "createBy",
          },
          {
            title: "创建日期",
            align: "center",
            dataIndex: "createTime",
            customRender: function (text) {
              return !text ? "" : text.length > 10 ? text.substr(0, 10) : text;
            },
          },
          {
            title: "更新人",
            align: "center",
            dataIndex: "updateBy",
          },
          {
            title: "更新日期",
            align: "center",
            dataIndex: "updateTime",
            customRender: function (text) {
              return !text ? "" : text.length > 10 ? text.substr(0, 10) : text;
            },
          },
          {
            title: "状态",
            align: "center",
            dataIndex: "status",
            scopedSlots: { customRender: "status" },
          },
          {
            title: "备注",
            align: "center",
            dataIndex: "remark",
          },
          {
            title: "操作",
            dataIndex: "action",
            align: "center",
            scopedSlots: { customRender: "action" },
          },
        ],
        url: {
          list: "/mes-quality/mesQcInspectIndexLibrary/rootList",
          childList: "/mes-quality/mesQcInspectIndexLibrary/childList",
          delete: "/mes-quality/mesQcInspectIndexLibrary/delete",
          deleteBatch: "/mes-quality/mesQcInspectIndexLibrary/deleteBatch",
          exportXlsUrl: "/mes-quality/mesQcInspectIndexLibrary/exportXls",
          importExcelUrl: "/mes-quality/mesQcInspectIndexLibrary/importExcel",
          getColumns: "/mes-quality/online/cgform/api/getColumns/",
          buttonAction: "/mes-quality/online/cgform/api/doButton",
        },
        expandedRowKeys: [],
        hasChildrenField: "hasChild",
        pidField: "pid",
        dictOptions: {},
      };
    },
    computed: {
      importExcelUrl() {
        return `${api.test}${this.url.importExcelUrl}`;
      },
      tableProps() {
        let _this = this;
        return {
          // 列表项是否可选择
          rowSelection: {
            selectedRowKeys: _this.selectedRowKeys,
            onChange: (selectedRowKeys) =>
                    (_this.selectedRowKeys = selectedRowKeys),
          },
        };
      },
      getWidth: function () {
        if (this.defColumns.length > 14) {
          return { width: "500px" };
        }
      },
      tableScroll: function () {
        if (this.columns.length > 13) {
          return { x: this.columns.length * 150 - 450 };
        }
      },
    },
    created() {
      this.getMethodList();
      this.initFirstProjectClassifyList();
      this.initSecondProjectClassifyList();
      this.initThirdProjectClassifyList();
      this.initInspectValueTypeList();
      this.initProjectTypeList();
      this.initInspectProjectCode();
      this.queryAllData();
      this.initButtonList();
      this.initColumns();
    },

    methods: {
      clickThenSelect(record) {
        return {
          on: {
            click: () => {
              if(record.id){
                this.rowId = record.id;
                //this.onSelectChange(record.id.split(","), [record]);
              }

            },
          },
        };
      },
      setRowClassName(record){
        return record.id === this.rowId ? 'clickRowStyl' : '';
      },
      //封装listToMap
      listToMap(list,name){
        let map = {};
        for(let i in list){
          map[list[i][name]] = list[i];
        }
        return map;
      },

      previewBtn(){
        this.drawerVisible = true;
      },

      initInspectValueTypeList(){
        getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'inspect_value_type'}).then(res=>{
          if(res.success){
            this.inspectValueTypeList = res.data;

          }
        })
      },

      initInspectProjectCode(){
        getAction('/basic-business/sys/fillRule/getFillRule/',{ruleCode:'mes_inspect_project_rule'}).then(res=>{
          if(res.success){
            this.inspectProjectCode = res.data;
          }
        })
      },

      initProjectTypeList(){
        getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'project_type'}).then(res=>{
          if(res.success){
            this.projectTypeList = res.data;
            this.projectTypeMap = this.listToMap(this.projectTypeList,'value');
          }
        })
      },
      getMethodList(){
        getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'mes_inspect_method'}).then(res=>{
          if(res.success){
            this.methodList = res.data;
            this.methodMap = this.listToMap(this.methodList,'value');
          }
        })
      },


      onDrawerClose(){
        this.drawerVisible = false;
      },

      openAddBtn(){
        if(this.currentState =2){
          this.formDataRest();
        }

        this.pModalVisible = true;
        this.currentState =1;
        this.pTitle = '新增';
        this.form.inspectProjectCode = this.inspectProjectCode;
      },

      openEditBtn(data){
        this.pModalVisible = true;
        this.currentState =2;
        this.pTitle = '编辑';

        this.editP = data;

        this.form={
          inspectProjectCode:data.inspectProjectCode,
          projectTypeId:data.projectTypeId,
          projectType:data.projectType,
          inspectValueType:data.inspectValueType,
          inspectProjectName:data.inspectProjectName,
          inspectMethod:data.inspectMethod,
          inspectStandard:data.inspectStandard,
          status:data.status
        }
        this.projectTypeIdChange();

        switch (data.projectTypeId) {
          case 1:

            if(this.projectClassifyMap1[data.projectClassifyId]){
              let item = this.projectClassifyMap1[data.projectClassifyId];
              this.form.projectClassifyId = item.id+'-'+item.mtypename;
              this.form.projectClassify = item.mtypename;
            }
            break;
          case 2:

            if(this.projectClassifyMap2[data.projectClassifyId]){
              let item = this.projectClassifyMap2[data.projectClassifyId];
              this.form.projectClassifyId = item.id+'-'+item.processmname;
              this.form.projectClassify = item.processmname;
            }
            break;
          case 3:

            if(this.projectClassifyMap3[data.projectClassifyId]){
              let item = this.projectClassifyMap3[data.projectClassifyId];
              this.form.projectClassifyId = data.projectClassifyId;
              this.form.projectClassify = item.title;
            }

            break;
          case 4:

            if(this.projectTypeMap[data.projectClassifyId]){
              let item = this.projectTypeMap[data.projectClassifyId];
              this.form.projectClassifyId = data.projectClassifyId;
              this.form.projectClassify = item.title;
            }

            break;
        }


      },

      pModalOk(){
        let data  =this.form;
        let flag = true;

        if(data.inspectValueType==2){
          if(data.inspectStandard==''){
            flag = false;
            this.$message.error("请输入检验标准");
          }
        }

        if(flag){
          this.$refs.ruleForm.validate(valid => {
            if (valid) {
              if(this.currentState==1){
                this.pAddOperation();
              }else if(this.currentState==2){
                this.pEditOperation();
              }
            } else {
              console.log('error submit!!');
              return false;
            }
          });
        }
      },


      formDataRest(){
        this.form= {
          inspectProjectCode:'',
          projectTypeId:'',
          projectType:'',
          projectClassifyId:'',
          projectClassify:'',
          inspectValueType:'',
          inspectProjectName:'',
          inspectMethod:'',
          inspectStandard:'',
          status:1
        };
      },

      pAddOperation(){
        let data = this.formDataConvert();
        postAction('/mes-quality/mesQcInspectIndexLibrary/add',data).then(res=>{
          if(res.success){
            this.pModalVisible =false;
            this.$message.success("修改成功");
            this.loadData();
            this.queryAllData();
            this.formDataRest();
            this.initInspectProjectCode();
          }else{
            this.$message.warning("检验项目已经存在");
          }
        })
      },

      pEditOperation(){
        let data = this.formDataConvert();

        let editP = this.editP;

        editP.inspectProjectCode=data.inspectProjectCode;
        editP.projectTypeId=data.projectTypeId;
        editP.projectType=data.projectType;
        editP.projectClassifyId=data.projectClassifyId;
        editP.projectClassify=data.projectClassify;
        editP.inspectValueType=data.inspectValueType;
        editP.inspectProjectName=data.inspectProjectName;
        editP.inspectMethod=data.inspectMethod;
        editP.inspectStandard=data.inspectStandard;
        editP.status=data.status;

        putAction('/mes-quality/mesQcInspectIndexLibrary/edit',editP).then(res=>{
          if(res.success){
            this.pModalVisible =false;
            this.$message.success("修改成功");
            this.loadData();
            this.queryAllData();
            this.formDataRest();
          }else{
            this.$message.warning("修改失败");
            this.loadData();
          }
        })
      },


      formDataConvert(){
        let data = this.form;
        let result = {
          inspectProjectCode:data.inspectProjectCode,
          projectTypeId:data.projectTypeId,
          projectType:data.projectType,
          inspectValueType:data.inspectValueType,
          inspectProjectName:data.inspectProjectName,
          inspectMethod:data.inspectMethod,
          inspectStandard:data.inspectStandard,
          status:data.status
        };
        switch (data.projectTypeId) {
          case 1:
            result.projectClassifyId = parseInt(data.projectClassifyId.split('-')[0]);
            if(this.projectClassifyMap[result.projectClassifyId]){
              result.projectClassify = this.projectClassifyMap1[result.projectClassifyId].mtypename;
            }
            break;
          case 2:
            result.projectClassifyId = parseInt(data.projectClassifyId.split('-')[0]);
            if(this.projectClassifyMap[result.projectClassifyId]){
              result.projectClassify = this.projectClassifyMap[result.projectClassifyId].processmname;
            }
            break;

          case 3:
            if(this.projectClassifyMap[data.projectClassifyId]){
              result.projectClassifyId=data.projectClassifyId
              result.projectClassify = this.projectClassifyMap[data.projectClassifyId].title;
            }
            break;
          case 4:
            if(this.projectTypeMap[data.projectClassifyId]){
              result.projectClassifyId=data.projectClassifyId
              result.projectClassify = this.projectTypeMap[data.projectClassifyId].title;
            }
            break;
        }

        return result;
      },


      inspectValueTypeChange(){
        this.form.inspectStandard = '';
      },

      projectTypeIdChange(){

        this.form.projectClassifyId = '';
        this.form.projectClassify = '';
        let projectTypeId = this.form.projectTypeId;
        if(this.projectTypeMap[projectTypeId]){
          this.form.projectType = this.projectTypeMap[projectTypeId].title;
        }

        switch(projectTypeId){
          case 1:
            this.changeFirstProjectClassifyList();
            break;
          case 2:
            this.changeSecondProjectClassifyList();
            break;
          case 3:
            this.changeThirdProjectClassifyList();
            break;
          case 4:
            let oldList = this.projectTypeList;
            let resultList = [];
            oldList.forEach(item=>{
              if(item.value!=projectTypeId){
                resultList.push(item);
              }
            })
            this.projectClassifyList = resultList;
            this.projectClassifyMap = this.listToMap(this.projectClassifyList,'value');
            break;
        }

      },

      projectTypeIdChange2(){

        this.toggleSearchStatus = true;
        Vue.set(this.queryParam,'projectClassifyId','');
        let projectTypeId = this.queryParam.projectTypeId;

        switch(projectTypeId){
          case 1:
            this.changeFirstProjectClassifyList2();
            break;
          case 2:
            this.changeSecondProjectClassifyList2();
            break;
          case 3:
            this.changeThirdProjectClassifyList2();
            break;
          case 4:
            let oldList = this.projectTypeList;
            let resultList = [];
            oldList.forEach(item=>{
              if(item.value!=projectTypeId){
                resultList.push(item);
              }
            })
            this.projectClassifyListT = resultList;
            break;
        }

      },

      changeFirstProjectClassifyList(){
        this.projectClassifyList = this.projectClassifyList1;
        this.projectClassifyMap = this.projectClassifyMap1;
      },

      changeSecondProjectClassifyList(){
        this.projectClassifyList = this.projectClassifyList2;
        this.projectClassifyMap = this.projectClassifyMap2;
      },

      changeThirdProjectClassifyList(){
        this.projectClassifyList = this.projectClassifyList3;
        this.projectClassifyMap = this.projectClassifyMap3;
      },
      changeFirstProjectClassifyList2(){
        this.projectClassifyListT = this.projectClassifyList1;
        this.projectClassifyMapT = this.projectClassifyMap1;
      },

      changeSecondProjectClassifyList2(){
        this.projectClassifyListT = this.projectClassifyList2;
        this.projectClassifyMapT = this.projectClassifyMap2;
      },

      changeThirdProjectClassifyList2(){
        this.projectClassifyListT = this.projectClassifyList3;
        this.projectClassifyMapT = this.projectClassifyMap3;
      },

      initFirstProjectClassifyList(){
        getAction('/basic-business/auto/baCptype/childList',{mtypelevel:3}).then(res=>{
          if(res.success){
            this.projectClassifyList1 = res.data;
            this.projectClassifyMap1 = this.listToMap(this.projectClassifyList1,'id');
          }
        })
      },

      initSecondProjectClassifyList(){
        /*  getAction('/mes-craft/craft/mesPeDefinition/getAllStation').then(res=>{*/
        getAction('/mes-craft/craft/mesPeDefinition/getAllSecondDef').then(res=>{
          if(res.success){
            this.projectClassifyList2 = res.data;
            this.projectClassifyMap2 = this.listToMap(this.projectClassifyList2,'id');
          }
        })
      },

      initThirdProjectClassifyList(){
        getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'inspect_type'}).then(res=>{
          if(res.success){
            this.projectClassifyList3 = res.data;
            this.projectClassifyMap3 = this.listToMap(this.projectClassifyList3,'value');
          }
        })
      },


      queryAllData(){
        getAction('/mes-quality/mesQcInspectIndexLibrary/selectAll').then(res=>{
          if(res.success){
            let list = res.data;
            let result = [];
            let set1 = new Set();
            let set2 = new Set();
            let set3 = new Set();
            let list1 = [];
            let list2 = [];
            let list3 = [];

            let key = 1;
            list.forEach(item=>{
              let projectType = item.projectType;
              let projectClassify = item.projectClassify;
              let inspectProjectName = item.inspectProjectName;

              let set1Index = projectType;
              let set2Index = projectType+projectClassify;
              let set3Index = projectType+projectClassify+inspectProjectName;

              if(!set1.has(set1Index)){
                set1.add(set1Index);
                list1.push(projectType);
              }
              if(!set2.has(set2Index)){
                set2.add(set2Index);
                list2.push({one:projectType,two:projectClassify});
              }
              if(!set3.has(set3Index)){
                set3.add(set3Index);
                list3.push({one:projectType,two:projectClassify,three:inspectProjectName});
              }

            })
            list3.forEach(item=>{
              let one = item.one;
              let two = item.two;
              let three = item.three;
              let oneFlag = true;
              result.forEach(jtem=>{
                if(one==jtem.title){
                  oneFlag = false;
                }
              })
              if(oneFlag){
                result.push({key:one+key,title:one,scopedSlots: {title: 'title'}})
                key = key+1;
              }
              result.forEach(jtem=>{
                if(one==jtem.title){
                  let twoFlag = true;
                  if(jtem.children){
                    jtem.children.forEach(o=>{
                      if(two==o.title){
                        twoFlag =false;
                      }
                    })
                    if(twoFlag){
                      jtem.children.push({key:two+key,title:two,scopedSlots: {title: 'title'}});
                      key = key+1;
                    }
                  }else{
                    jtem.children=[{key:two+key,title:two,scopedSlots: {title: 'title'}}]
                    key = key+1;
                  }
                }
              })
              result.forEach(i=>{
                if(one==i.title){
                  i.children.forEach(j=>{
                    if(two==j.title){
                      let threeFlag = true;
                      if(j.children){
                        j.children.forEach(k=>{
                          if(three==k.title){
                            threeFlag=false;
                          }
                        })
                        if(threeFlag){
                          j.children.push({key:three+key,title:three,scopedSlots: {title: 'title'}})
                          key = key+1;
                        }

                      }else{
                        j.children = [{key:three+key,title:three,scopedSlots: {title: 'title'}}];
                        key = key+1;
                      }
                    }
                  })
                }
              })
            })

            this.treeDataFirst = result;
            this.treeData = result;
          }
        })
      },




      deleteBtn(id){
        deleteAction('/mes-quality/mesQcInspectIndexLibrary/delete/'+id).then(res=>{
          if(res.success){
            this.$message.success("删除成功！");
            this.loadData();
          }else{
            this.$message.warning(res.msg);
          }
        })
      },

      clickTree(title){

        if(this.defaultExpandedKeys.indexOf(title)==-1){
          this.defaultExpandedKeys.push(title)
        }else{
          console.log((this.defaultExpandedKeys.indexOf(title)))

          let index = this.defaultExpandedKeys.indexOf(title);
          this.defaultExpandedKeys.splice(index, 1)
        }
      },


      treeSearchChange(e){
        let str = e.target.value;
        this.searchValue= str;
        if(str==''){
          this.defaultExpandedKeys= [];
        }else{
          this.setDefaultExpandedKeys(str);
        }
        this.autoExpandParent=true;
      },

      unique5(arr){
        let x = new Set(arr);
        return [...x];
      },
      onExpand(expandedKeys) {

        console.log(expandedKeys)
        let oldExpandedKeys = this.selectTreeKey;
        let opeKey = '';
        let isDelete= false;
        if(oldExpandedKeys.length>expandedKeys.length){
          isDelete = true;
          oldExpandedKeys.forEach(i=>{
            let hasFlag = false;
            expandedKeys.forEach(j=>{
              if(i==j){
                hasFlag =true;
              }
            })

            if(!hasFlag){
              opeKey = i;
            }
          })
        }

        if(oldExpandedKeys.length<expandedKeys.length){
          isDelete = false;
          expandedKeys.forEach(i=>{
            let hasFlag = false;
            oldExpandedKeys.forEach(j=>{
              if(i==j){
                hasFlag =true;
              }
            })

            if(!hasFlag){
              opeKey = i;
            }
          })
        }
        this.selectTreeKey = expandedKeys;
        this.clickTree(opeKey);

        /* this.expandedKeys = expandedKeys;
         this.autoExpandParent = false;*/
      },

      convertTwoArray(expandedKeys){

      },


      setDefaultExpandedKeys(str){

        let defaultExpandedKeys = [];
        this.treeData.forEach(i=>{

          if(i.title.indexOf(this.searchValue)>-1){

            defaultExpandedKeys.push(i.key)
          }
          if(i.children){
            i.children.forEach(j=>{
              if(j.title.indexOf(this.searchValue)>-1){
                defaultExpandedKeys.push(i.key)
                defaultExpandedKeys.push(j.key)
              }
              if(j.children){
                j.children.forEach(k=>{
                  if(k.title.indexOf(this.searchValue)>-1){
                    defaultExpandedKeys.push(i.key)
                    defaultExpandedKeys.push(j.key)
                  }
                })
              }
            })
          }
        })


        defaultExpandedKeys = this.unique5(defaultExpandedKeys)

        this.defaultExpandedKeys= defaultExpandedKeys;
        this.selectTreeKey = defaultExpandedKeys;

        console.log(defaultExpandedKeys)
      },


      //确定按钮
      handleSearch(selectedKeys, confirm, dataIndex) {
        confirm();
        this.searchText = selectedKeys[0];
        this.searchedColumn = dataIndex;
      },
      //取消按钮
      handleReset(clearFilters) {
        clearFilters();
        this.searchText = "";
      },
      //确定时间
      handleSearchDate(selectedKeys, confirm, dataIndex) {
        confirm();
        this.searchText = selectedKeys[0];
        this.searchedColumn = dataIndex;
        this.searchQuery();
      },
      // 清除时间
      handleResetDate(clearFilters, begin, end) {
        if (this.queryParam[begin] || this.queryParam[end]) {
          this.queryParam[begin] = "";
          this.queryParam[end] = "";
          clearFilters();
          this.searchText = "";
          this.searchQuery();
        } else {
          clearFilters();
          this.searchText = "";
        }
      },
      getKey() {
        const dataItem = [];
        setTimeout(() => {
          this.columns.forEach((item) => {
            dataItem.push({ text: item.title, value: item.dataIndex });
          });
        }, 100);
        return dataItem;
      },
      //
      getControl(dic) {
        const dataItem = [];
        initDictOptions(dic).then((res) => {
          res.data.forEach((item) => {
            dataItem.push({ text: item.text, value: item.value });
          });
        });
        return dataItem;
      },
      initColumns() {
        //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
        //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

        var key = this.$route.name + ":colsettings";
        let colSettings = Vue.ls.get(key);
        if (colSettings == null || colSettings == undefined) {
          let allSettingColumns = [];
          this.defColumns.forEach(function (item, i, array) {
            allSettingColumns.push(item.dataIndex);
          });
          this.settingColumns = allSettingColumns;
          this.columns = this.defColumns;
        } else {
          this.settingColumns = colSettings;
          const cols = this.defColumns.filter((item) => {
            if (item.key == "rowIndex" || item.dataIndex == "action") {
              return true;
            }
            if (colSettings.includes(item.dataIndex)) {
              return true;
            }
            return false;
          });
          this.columns = cols;
        }
      },
      //列设置更改事件
      onColSettingsChange(checkedValues) {
        var key = this.$route.name + ":colsettings";
        Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000);
        this.settingColumns = checkedValues;
        const cols = this.defColumns.filter((item) => {
          if (item.key == "rowIndex" || item.dataIndex == "action") {
            return true;
          }
          if (this.settingColumns.includes(item.dataIndex)) {
            return true;
          }
          return false;
        });
        this.columns = cols;
      },

      //高级查询方法
      handleSuperQuery(arg) {
        if (!arg) {
          this.superQueryParams = "";
          this.superQueryFlag = false;
        } else {
          this.superQueryFlag = true;
          this.superQueryParams = JSON.stringify(arg);
        }
        this.loadData();
      },
      // 获取查询条件
      getQueryParams() {
        let sqp = {};
        if (this.superQueryParams) {
          sqp["superQueryParams"] = encodeURI(this.superQueryParams);
        }
        var param = Object.assign(sqp, this.queryParam, this.isorter);
        param.field = this.getQueryField();
        param.pageNo = this.ipagination.current;
        param.limit = this.ipagination.pageSize;
        return filterObj(param);
      },
      loadData(arg) {
        if (arg == 1) {
          this.ipagination.current = 1;
        }
        this.loading = true;
        this.expandedRowKeys = [];
        let params = this.getQueryParams();

        if(params.projectClassifyId&&params.projectClassifyId!=''){
          params.projectClassifyId = params.projectClassifyId.split('-')[0];
        }
        return new Promise((resolve) => {
          getAction(this.url.list, params).then((res) => {
            if (res.success) {
              let result = res.data;
              if (Number(result.total) > 0) {
                this.ipagination.total = Number(result.total);
                this.dataSource = this.getDataByResult(res.data.records);
                resolve();
              } else {
                this.ipagination.total = 0;
                this.dataSource = [];
              }
            } else {
              this.$message.warning(res.msg);
            }

          }).then(res=>{
            this.loading = false;
          });
        });
      },
      getDataByResult(result) {
        return result.map((item) => {
          //判断是否标记了带有子节点
          if (item[this.hasChildrenField] == "1") {
            let loadChild = {
              id: item.id + "_loadChild",
              name: "loading...",
              isLoading: true,
            };
            item.children = [loadChild];
          }
          return item;
        });
      },
      handleExpand(expanded, record) {
        // 判断是否是展开状态
        if (expanded) {
          this.expandedRowKeys.push(record.id);
          if (
                  record.children.length > 0 &&
                  record.children[0].isLoading === true
          ) {
            let params = this.getQueryParams(); //查询条件
            params[this.pidField] = record.id;
            getAction(this.url.childList, params).then((res) => {
              if (res.success) {
                if (res.data && res.data.length > 0) {
                  record.children = this.getDataByResult(res.data);
                  this.dataSource = [...this.dataSource];
                } else {
                  record.children = "";
                  record.hasChildrenField = "0";
                }
              } else {
                this.$message.warning(res.msg);
              }
            });
          }
        } else {
          let keyIndex = this.expandedRowKeys.indexOf(record.id);
          if (keyIndex >= 0) {
            this.expandedRowKeys.splice(keyIndex, 1);
          }
        }
      },
      initDictConfig() {},

      // 弹出窗组件
      showDemoModal() {
        this.$refs.modalCompon.modalShow();
      },
      // 点击btn获取数据
      btnGetData(tableName, title) {
        getAction(`${this.url.getColumns}`, {
          tableName: tableName,
        }).then((res) => {
          if (res.code == 0) {
            this.queryInfo = res.data.columns;
            this.title = title;
            this.dictOptions = res.data.dictOptions;
            this.showDemoModal();
          } else {
            this.$message.warning(res.msg);
          }
        });
      },

      //筛选分组
      getGroupTag(arrList) {
        let arr = [];
        var map = {},
                dest = [];
        arrList.forEach((item, index) => {
          if (item.groupTag) {
            arr.push(item);
          }
        });
        for (var i = 0; i < arr.length; i++) {
          var ai = arr[i];
          if (!map[ai.groupTag]) {
            dest.push({
              groupTag: ai.groupTag,
              name: ai.groupName,
              data: [ai],
            });
            map[ai.groupTag] = ai;
          } else {
            for (var j = 0; j < dest.length; j++) {
              var dj = dest[j];
              if (dj.groupTag == ai.groupTag) {
                dj.data.push(ai);
                break;
              }
            }
          }
        }
        this.groupTag = dest;
        console.log(dest);
      },
      showLinkButton(item, record) {
        let btn = new ButtonExpHandler(item.exp, record);
        return btn.show;
      },
      initButtonList() {
        getAction(`${this.url.getColumns}8ac49ec7733bce4801734c1e57a600ec`).then(
                (res) => {
                  console.log("--获取自定义按钮->>", res);
                  if (res.success) {
                    this.code = res.data.code;
                    this.initCgButtonList(res.data.cgButtonList);
                    this.initCgEnhanceJs(res.data.enhanceJs);
                    this.getGroupTag(res.data.cgButtonList);
                  } else {
                    this.$message.warning(res.msg);
                  }
                }
        );
      },
      initCgEnhanceJs(enhanceJs) {
        //console.log("--onlineList-js增强",enhanceJs)
        if (enhanceJs) {
          let Obj = eval("(" + enhanceJs + ")");
          this.EnhanceJS = new Obj(getAction, postAction, deleteAction);
          this.cgButtonJsHandler("created");
        } else {
          this.EnhanceJS = "";
        }
      },
      initCgButtonList(btnList) {
        let linkArr = [];
        let buttonArr = [];
        if (btnList && btnList.length > 0) {
          for (let i = 0; i < btnList.length; i++) {
            let temp = btnList[i];
            if (temp.buttonStyle == "button") {
              buttonArr.push(temp);
            } else if (temp.buttonStyle == "link") {
              linkArr.push(temp);
            }
          }
        }
        this.cgButtonLinkList = [...linkArr];
        this.cgButtonList = [...buttonArr];
        console.log("链接增强", this.cgButtonLinkList);
      },
      cgButtonJsHandler(buttonCode) {
        if (this.EnhanceJS[buttonCode]) {
          this.EnhanceJS[buttonCode](this);
        }
      },
      cgButtonActionHandler(buttonCode) {
        //处理自定义button的 需要配置该button自定义sql
        if (!this.selectedRowKeys || this.selectedRowKeys.length == 0) {
          this.$message.warning("请先选中一条记录");
          return false;
        }
        if (this.selectedRowKeys.length > 1) {
          this.$message.warning("请只选中一条记录");
          return false;
        }
        let params = {
          formId: this.code,
          buttonCode: buttonCode,
          dataId: this.selectedRowKeys[0],
        };
        console.log("自定义按钮请求后台参数：", params);
        postAction(this.url.buttonAction, params).then((res) => {
          if (res.success) {
            this.loadData();
            this.$message.success("处理完成!");
          } else {
            this.$message.warning("处理失败!");
          }
        });
      },
      cgButtonLinkHandler(record, buttonCode, optType) {
        if (optType == "js") {
          if (this.EnhanceJS[buttonCode]) {
            this.EnhanceJS[buttonCode](this, record);
          }
        } else if (optType == "action") {
          let params = {
            formId: this.code,
            buttonCode: buttonCode,
            dataId: record.id,
          };
          console.log("自定义按钮link请求后台参数：", params);
          postAction(this.url.buttonAction, params).then((res) => {
            if (res.success) {
              this.loadData();
              this.$message.success("处理完成!");
            } else {
              this.$message.warning("处理失败!");
            }
          });
        }
      },
      modalFormOk(formData, arr) {
        if (!formData.id) {
          this.addOk(formData, arr);
        } else {
          if (!arr) {
            this.loadData();
          } else {
            this.editOk(formData, this.dataSource);
            this.dataSource = [...this.dataSource];
          }
        }
      },
      editOk(formData, arr) {
        if (arr && arr.length > 0) {
          for (let i = 0; i < arr.length; i++) {
            if (arr[i].id == formData.id) {
              arr[i] = formData;
              break;
            } else {
              this.editOk(formData, arr[i].children);
            }
          }
        }
      },
      async addOk(formData, arr) {
        if (!formData[this.pidField]) {
          this.loadData();
        } else {
          this.expandedRowKeys = [];
          for (let i of arr) {
            await this.expandTreeNode(i);
          }
        }
      },
      expandTreeNode(nodeId) {
        return new Promise((resolve, reject) => {
          this.getFormDataById(nodeId, this.dataSource);
          let row = this.parentFormData;
          this.expandedRowKeys.push(nodeId);
          let params = this.getQueryParams(); //查询条件
          params[this.pidField] = nodeId;
          getAction(this.url.childList, params).then((res) => {
            if (res.success) {
              if (res.data && res.data.length > 0) {
                row.children = this.getDataByResult(res.data);
                this.dataSource = [...this.dataSource];
                resolve();
              } else {
                reject();
              }
            } else {
              reject();
            }
          });
        });
      },
      getFormDataById(id, arr) {
        if (arr && arr.length > 0) {
          for (let i = 0; i < arr.length; i++) {
            if (arr[i].id == id) {
              this.parentFormData = arr[i];
            } else {
              this.getFormDataById(id, arr[i].children);
            }
          }
        }
      },
    },
  };
</script>
<style scoped>
  @import '~@assets/less/common.less';
  /deep/.clickRowStyl td{
    background:#00b4ed !important;
  }

  /deep/.ant-table-tbody.clickRowStyl:hover>td {
    background-color:#00b4ed
  }
</style>